草庐IT

c++ - 了解 `std::is_move_constructible`

全部标签

c - Ruby C 扩展 API 问题

所以,最近我不幸地需要为Ruby做一个C扩展(因为性能)。因为我在理解上有问题VALUE(并且仍然如此),所以我查看了Ruby源代码并发现:typedefunsignedlongVALUE;(LinktoSource,但您会注意到它还有其他一些“方法”,但我认为它本质上是一个long;如果我错了,请纠正我)。因此,在进一步调查时,我发现了一个有趣的blogpost,其中说:"...insomecasestheVALUEobjectcouldBEthedatainsteadofPOINTINGTOthedata."令我困惑的是,当我尝试从Ruby将字符串传递给C并使用RSTRING_PT

c - 在 C 中扩展 ruby​​ - 如何指定函数的默认参数值?

我正在尝试为将生成一个类的ruby​​编写C扩展。我正在研究如何为类定义一些默认参数。例如,如果我在ruby​​中有这个类decleration:classMyClassdefinitialize(name,age=10)@name=name@age=ageendend您可以使用mc=MyClass.new("blah")初始化它,年龄参数将在内部设置。我如何在C中执行此操作?到目前为止我得到了这个,但这迫使进入另一个论点:require"ruby.h"staticVALUEmy_init(VALUEself,VALUEname,VALUEage){rb_iv_set(self,"@n

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby - 我在 Mac OS X 上收到 "RVM is not a function"错误,并且没有发布的解决方案有效

我在MacOSx10.8.2(“MountainLion”)上,我成功安装了RVM1.17.8及其依赖项。我可以使用它来使用rvminstall1.9.2安装Ruby版本,但我无法执行rvmuse没有收到此错误:RVMisnotafunction,selectingrubieswith'rvmuse...'willnotwork.Youneedtochangeyourterminalemulatorpreferencestoallowloginshell.Sometimesitisrequiredtouse`/bin/bash--login`asthecommand.Pleasevis

ruby 摩卡 : is there an equivalent to rspec-mocks' #and_call_original?

Rspec-mocks具有expect(some_object).toreceive(:some_method).and_call_original。我可以用Mocha做这个吗?如果可以,怎么做?some_object.expects(:some_method).......什么? 最佳答案 我相当确定没有办法做到这一点。浏览sourcecode,有评论提到完全替换了原来的方法。#Theoriginalimplementationofthemethodisreplacedduringthetestandthenrestoredatt

ruby - sinatra config.ru : what is the configure block for?

我将Sinatra与Apache和“经典”风格的Phusion-Passenger一起使用:#config.rurequire'sinatra'configuredo....endrequire'./app'runSinatra::Application我想定义一些东西。在配置block内部或外部定义它有什么区别?#config.rurequire'sinatra'#A)Definingloggerhererack=File.new("logs/rack.log","a+")useRack::CommonLogger,rack#B)GlobalvariableshereLOGGER=L

c - 如何在 Mac OS X 上使用 ulimit 或每个进程为 C 或 Ruby 程序更改堆栈大小?

似乎为C程序或Ruby程序(使用C堆栈)设置堆栈大小的推荐方法是使用ulimit。在Bash外壳中。但是$ulimit-s8192$ulimit-s16384-bash:ulimit:stacksize:cannotmodifylimit:Operationnotpermitted和sudo也没有帮助。有没有办法将其设置为16MB、32MB或64MB?我认为应该有一种方法可以在每次程序调用时设置它,而不是同时设置系统范围的参数?现在8192可能意味着8MB,如果与一个进程可以使用的内存量相比,这是非常小的,有时最多2GB的RAM。(更新注释:ulimit-a可以显示其当前值)。(更新2

ruby - 了解类方法的 method_added

我想在将实例和类方法添加到某个类时施展魔法。因此我尝试了以下方法:moduleMagicdefself.included(base)base.extendClassMethodsendmoduleClassMethodsdefmethod_added(name)puts"classmethod'#{name}'added"enddefsome_class_methodputs"someclassmethod"endendendclassFooincludeMagicdefself.method_added(name)puts"instancemethod#{name}added"end

ruby-on-rails - ruby rails : How do you check if a file is an image?

如何检查文件是否为图像?我想你可以使用这样的方法:defimage?(file)file.to_s.include?(".gif")orfile.to_s.include?(".png")orfile.to_s.include?(".jpg")end但这可能有点低效而且不正确。有什么想法吗?(我正在使用回形针插件,顺便说一句,但我没有看到任何方法来确定文件是否是回形针中的图像) 最佳答案 请检查一次MIME::Types.type_for('tmp/img1.jpg').first.try(:media_type)=>"image"

ruby-on-rails - I18n : How to check if a translation key/value pairs is missing?

我正在使用RubyonRails3.1.0和I18ngem.我(正在实现一个插件)我想在运行时检查I18n是否缺少翻译键/值对,如果是,则使用自定义字符串。也就是说,我有:validates:link_url,:format=>{:with=>REGEX,:message=>I18n.t('custom_invalid_format',:scope=>'activerecord.errors.messages')}如果.yml文件中没有如下代码activerecord:errors:messages:custom_invalid_format:Thisisthetesterrormes